package org.geektimes.projects.user.web.controller;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.service.UserService;
import org.geektimes.projects.user.service.UserServiceImpl;
import org.geektimes.web.mvc.controller.PageController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Path;

/**
 * @author Lee
 * @date 2021/3/1 10:56
 */
@Path("/register")
public class RegisterController implements PageController {

    /**
     * 用户 service
     */
    private UserService userService;

    /**
     * 注入service
     */
    public RegisterController() {
        userService = new UserServiceImpl();
    }


    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws Throwable {
        System.out.println("userName: " + request.getParameter("userName"));
        System.out.println("password: " + request.getParameter("password"));
        System.out.println("email: " + request.getParameter("email"));
        System.out.println("phoneNumber: " + request.getParameter("phoneNumber"));

        // 用户信息拼装
        User user = new User();
        user.setName(request.getParameter("userName"));
        user.setPassword(request.getParameter("password"));
        user.setEmail(request.getParameter("email"));
        user.setPhoneNumber(request.getParameter("phoneNumber"));

        // 用户信息注册
        userService.register(user);

        return "success.jsp";
    }
}
